package com.ctgu.programme;

import java.util.Scanner;

public class Count {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[10000];
        int[] m = new int[10000];//保存包含当前数的最大和
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        m[0] = a[0];
        for (int i = 1; i < n; i++) {
            if(m[i-1] > 0)
                m[i] = m[i-1] + a[i];
            else
                m[i] = a[i];
        }
        int ans = m[0];
        for(int i = 1; i < n; i++){
            ans = Math.max(ans,m[i]);
        }
        System.out.printf("子数组之和的最大值为%d",ans);
    }
}
